﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Runda.CMS.Common.Utility
{
    /// <summary>
    /// 
    /// </summary>
    public class ConfigHelper
    {
        public static string CacheExtendedFormatTime
        {
            get { return ReadConfig("CacheExtendedFormatTime"); }
        }
        public static string PersistenceString
        {
            get { return ReadConfig("PersistenceString"); }
        }
        public static string LogCategoryConfig
        {
            get { return ReadConfig("LogCategoryConfig"); }
        }

        public static string RemotingUrl
        {
            get { return ReadConfig("RemotingUrl"); }
        }

        /// <summary>
        /// 是否使用Cache
        /// </summary>
        public static bool IsCacheUsed
        {
            get
            {
                return ReadBoolConfig("IsCacheUsed");
            }
        }


        public static bool ReadBoolConfig(string key)
        {
            string val = ReadConfig(key);
            if (string.IsNullOrEmpty(val) || val.ToLower() != "true")
                return false;
            return true;
        }

        public static string ReadConfig(string key)
        {
            return ConfigurationManager.AppSettings[key];
        }

        public static int ReadIntConfig(string key)
        {
            string port = ConfigHelper.ReadConfig(key).Trim();
            int p = 0;
            int.TryParse(port, out p);
            return p;
        }

    }
}
